#!/usr/bin/env python

###########################################################################
#  Copyright 2010 Jim Pulokas
#
#  This file is part of focusfun.
#  
#  focusfun is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#  
#  focusfun is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with focusfun.  If not, see <http://www.gnu.org/licenses/>.
###########################################################################

import gstgrabber
import v4l2focuser

def grab_sequence(prefix, fseries):
	grabber = gstgrabber.Grabber('/dev/video0')
	focuser = v4l2focuser.Focuser(grabber.v4l2_fd)
	for i,f in enumerate(fseries):
		print i,f
		focuser.set(f)
		filename = '%s-%03d-%03d.png' % (prefix, i,f,)
		grabber.grab_to_file(filename)
		print 'saved', filename

if __name__ == '__main__':
	import sys
	prefix = sys.argv[1]
	start = int(sys.argv[2])
	stop = int(sys.argv[3])
	step = int(sys.argv[4])

	fseries = range(start, stop, step)
	grab_sequence(prefix, fseries)
